<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Template promise&lt;&gt;</title>
<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="../../../index.html" title="Chapter&#160;1.&#160;Fiber">
<link rel="up" href="../futures.html" title="Futures">
<link rel="prev" href="future.html" title="Future">
<link rel="next" href="packaged_task.html" title="Template packaged_task&lt;&gt;">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="future.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../futures.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="packaged_task.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="fiber.synchronization.futures.promise"></a><a name="class_promise"></a><a class="link" href="promise.html" title="Template promise&lt;&gt;">Template
        <code class="computeroutput"><span class="identifier">promise</span><span class="special">&lt;&gt;</span></code></a>
</h4></div></div></div>
<p>
          A <a class="link" href="promise.html#class_promise"><code class="computeroutput">promise&lt;&gt;</code></a> provides a mechanism to store a value (or
          exception) that can later be retrieved from the corresponding <a class="link" href="future.html#class_future"><code class="computeroutput">future&lt;&gt;</code></a> object.
          <code class="computeroutput"><span class="identifier">promise</span><span class="special">&lt;&gt;</span></code>
          and <code class="computeroutput"><span class="identifier">future</span><span class="special">&lt;&gt;</span></code>
          communicate via their underlying <a class="link" href="future.html#shared_state">shared state</a>.
        </p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">fiber</span><span class="special">/</span><span class="identifier">future</span><span class="special">/</span><span class="identifier">promise</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>

<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span>
<span class="keyword">namespace</span> <span class="identifier">fibers</span> <span class="special">{</span>

<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">R</span> <span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">promise</span> <span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
    <span class="identifier">promise</span><span class="special">();</span>

    <span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <a href="http://en.cppreference.com/w/cpp/concept/Allocator" target="_top"><code class="computeroutput"><span class="identifier">Allocator</span></code></a> <span class="special">&gt;</span>
    <span class="identifier">promise</span><span class="special">(</span> <a href="http://en.cppreference.com/w/cpp/memory/allocator_arg_t" target="_top"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">allocator_arg_t</span></code></a><span class="special">,</span> <span class="identifier">Allocator</span><span class="special">);</span>

    <span class="identifier">promise</span><span class="special">(</span> <span class="identifier">promise</span> <span class="special">&amp;&amp;)</span> <span class="keyword">noexcept</span><span class="special">;</span>

    <span class="identifier">promise</span> <span class="special">&amp;</span> <span class="keyword">operator</span><span class="special">=(</span> <span class="identifier">promise</span> <span class="special">&amp;&amp;)</span> <span class="keyword">noexcept</span><span class="special">;</span>

    <span class="identifier">promise</span><span class="special">(</span> <span class="identifier">promise</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="special">=</span> <span class="keyword">delete</span><span class="special">;</span>

    <span class="identifier">promise</span> <span class="special">&amp;</span> <span class="keyword">operator</span><span class="special">=(</span> <span class="identifier">promise</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="special">=</span> <span class="keyword">delete</span><span class="special">;</span>

    <span class="special">~</span><span class="identifier">promise</span><span class="special">();</span>

    <span class="keyword">void</span> <span class="identifier">swap</span><span class="special">(</span> <span class="identifier">promise</span> <span class="special">&amp;)</span> <span class="keyword">noexcept</span><span class="special">;</span>

    <span class="identifier">future</span><span class="special">&lt;</span> <span class="identifier">R</span> <span class="special">&gt;</span> <span class="identifier">get_future</span><span class="special">();</span>

    <span class="keyword">void</span> <span class="identifier">set_value</span><span class="special">(</span> <span class="identifier">R</span> <span class="keyword">const</span><span class="special">&amp;);</span>  <span class="comment">// member only of generic promise template</span>
    <span class="keyword">void</span> <span class="identifier">set_value</span><span class="special">(</span> <span class="identifier">R</span> <span class="special">&amp;&amp;);</span>      <span class="comment">// member only of generic promise template</span>
    <span class="keyword">void</span> <span class="identifier">set_value</span><span class="special">(</span> <span class="identifier">R</span> <span class="special">&amp;);</span>       <span class="comment">// member only of promise&lt; R &amp; &gt; template</span>
    <span class="keyword">void</span> <span class="identifier">set_value</span><span class="special">();</span>           <span class="comment">// member only of promise&lt; void &gt; template</span>

    <span class="keyword">void</span> <span class="identifier">set_exception</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">exception_ptr</span> <span class="identifier">p</span><span class="special">);</span>
<span class="special">};</span>

<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">R</span> <span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">swap</span><span class="special">(</span> <span class="identifier">promise</span><span class="special">&lt;</span> <span class="identifier">R</span> <span class="special">&gt;</span> <span class="special">&amp;,</span> <span class="identifier">promise</span><span class="special">&lt;</span> <span class="identifier">R</span> <span class="special">&gt;</span> <span class="special">&amp;)</span> <span class="keyword">noexcept</span><span class="special">;</span>

<span class="special">}</span>
</pre>
<h6>
<a name="fiber.synchronization.futures.promise.h0"></a>
          <span><a name="fiber.synchronization.futures.promise.default_constructor"></a></span><a class="link" href="promise.html#fiber.synchronization.futures.promise.default_constructor">Default
          constructor</a>
        </h6>
<pre class="programlisting"><span class="identifier">promise</span><span class="special">();</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl>
<dt><span class="term">Effects:</span></dt>
<dd><p>
                Creates a promise with an empty <a class="link" href="future.html#shared_state">shared
                state</a>.
              </p></dd>
<dt><span class="term">Throws:</span></dt>
<dd><p>
                Exceptions caused by memory allocation.
              </p></dd>
</dl>
</div>
<h6>
<a name="fiber.synchronization.futures.promise.h1"></a>
          <span><a name="fiber.synchronization.futures.promise.constructor"></a></span><a class="link" href="promise.html#fiber.synchronization.futures.promise.constructor">Constructor</a>
        </h6>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <a href="http://en.cppreference.com/w/cpp/concept/Allocator" target="_top"><code class="computeroutput"><span class="identifier">Allocator</span></code></a> <span class="special">&gt;</span>
<span class="identifier">promise</span><span class="special">(</span> <a href="http://en.cppreference.com/w/cpp/memory/allocator_arg_t" target="_top"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">allocator_arg_t</span></code></a><span class="special">,</span> <span class="identifier">Allocator</span> <span class="identifier">alloc</span><span class="special">);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl>
<dt><span class="term">Effects:</span></dt>
<dd><p>
                Creates a promise with an empty <a class="link" href="future.html#shared_state">shared
                state</a> by using <code class="computeroutput"><span class="identifier">alloc</span></code>.
              </p></dd>
<dt><span class="term">Throws:</span></dt>
<dd><p>
                Exceptions caused by memory allocation.
              </p></dd>
<dt><span class="term">See also:</span></dt>
<dd><p>
                <a href="http://en.cppreference.com/w/cpp/memory/allocator_arg_t" target="_top"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">allocator_arg_t</span></code></a>
              </p></dd>
</dl>
</div>
<h6>
<a name="fiber.synchronization.futures.promise.h2"></a>
          <span><a name="fiber.synchronization.futures.promise.move_constructor"></a></span><a class="link" href="promise.html#fiber.synchronization.futures.promise.move_constructor">Move constructor</a>
        </h6>
<pre class="programlisting"><span class="identifier">promise</span><span class="special">(</span> <span class="identifier">promise</span> <span class="special">&amp;&amp;</span> <span class="identifier">other</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl>
<dt><span class="term">Effects:</span></dt>
<dd><p>
                Creates a promise by moving the <a class="link" href="future.html#shared_state">shared
                state</a> from <code class="computeroutput"><span class="identifier">other</span></code>.
              </p></dd>
<dt><span class="term">Postcondition:</span></dt>
<dd><p>
                <code class="computeroutput"><span class="identifier">other</span></code> contains no
                valid shared state.
              </p></dd>
<dt><span class="term">Throws:</span></dt>
<dd><p>
                Nothing.
              </p></dd>
</dl>
</div>
<h6>
<a name="fiber.synchronization.futures.promise.h3"></a>
          <span><a name="fiber.synchronization.futures.promise.destructor"></a></span><a class="link" href="promise.html#fiber.synchronization.futures.promise.destructor">Destructor</a>
        </h6>
<pre class="programlisting"><span class="special">~</span><span class="identifier">promise</span><span class="special">();</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl>
<dt><span class="term">Effects:</span></dt>
<dd><p>
                Destroys <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
                and abandons the <a class="link" href="future.html#shared_state">shared state</a>
                if shared state is ready; otherwise stores <code class="computeroutput"><span class="identifier">future_error</span></code>
                with error condition <code class="computeroutput"><span class="identifier">future_errc</span><span class="special">::</span><span class="identifier">broken_promise</span></code>
                as if by <a class="link" href="promise.html#promise_set_exception"><code class="computeroutput">promise::set_exception()</code></a>: the shared
                state is set ready.
              </p></dd>
</dl>
</div>
<p>
          </p>
<h5>
<a name="promise_operator_assign_bridgehead"></a>
  <span><a name="promise_operator_assign"></a></span>
  <a class="link" href="promise.html#promise_operator_assign">Member
          function <code class="computeroutput">operator=</code>()</a>
</h5>
<p>
        </p>
<pre class="programlisting"><span class="identifier">promise</span> <span class="special">&amp;</span> <span class="keyword">operator</span><span class="special">=(</span> <span class="identifier">promise</span> <span class="special">&amp;&amp;</span> <span class="identifier">other</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl>
<dt><span class="term">Effects:</span></dt>
<dd><p>
                Transfers the ownership of <a class="link" href="future.html#shared_state">shared state</a>
                to <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>.
              </p></dd>
<dt><span class="term">Postcondition:</span></dt>
<dd><p>
                <code class="computeroutput"><span class="identifier">other</span></code> contains no
                valid shared state.
              </p></dd>
<dt><span class="term">Throws:</span></dt>
<dd><p>
                Nothing.
              </p></dd>
</dl>
</div>
<p>
          </p>
<h5>
<a name="promise_swap_bridgehead"></a>
  <span><a name="promise_swap"></a></span>
  <a class="link" href="promise.html#promise_swap">Member function <code class="computeroutput">swap</code>()</a>
</h5>
<p>
        </p>
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">swap</span><span class="special">(</span> <span class="identifier">promise</span> <span class="special">&amp;</span> <span class="identifier">other</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl>
<dt><span class="term">Effects:</span></dt>
<dd><p>
                Swaps the <a class="link" href="future.html#shared_state">shared state</a> between
                other and <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>.
              </p></dd>
<dt><span class="term">Throws:</span></dt>
<dd><p>
                Nothing.
              </p></dd>
</dl>
</div>
<p>
          </p>
<h5>
<a name="promise_get_future_bridgehead"></a>
  <span><a name="promise_get_future"></a></span>
  <a class="link" href="promise.html#promise_get_future">Member
          function <code class="computeroutput">get_future</code>()</a>
</h5>
<p>
        </p>
<pre class="programlisting"><span class="identifier">future</span><span class="special">&lt;</span> <span class="identifier">R</span> <span class="special">&gt;</span> <span class="identifier">get_future</span><span class="special">();</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl>
<dt><span class="term">Returns:</span></dt>
<dd><p>
                A <a class="link" href="future.html#class_future"><code class="computeroutput">future&lt;&gt;</code></a> with the same <a class="link" href="future.html#shared_state">shared
                state</a>.
              </p></dd>
<dt><span class="term">Throws:</span></dt>
<dd><p>
                <code class="computeroutput"><span class="identifier">future_error</span></code> with
                <code class="computeroutput"><span class="identifier">future_errc</span><span class="special">::</span><span class="identifier">future_already_retrieved</span></code> or <code class="computeroutput"><span class="identifier">future_errc</span><span class="special">::</span><span class="identifier">no_state</span></code>.
              </p></dd>
</dl>
</div>
<p>
          </p>
<h5>
<a name="promise_set_value_bridgehead"></a>
  <span><a name="promise_set_value"></a></span>
  <a class="link" href="promise.html#promise_set_value">Member function
          <code class="computeroutput">set_value</code>()</a>
</h5>
<p>
        </p>
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">set_value</span><span class="special">(</span> <span class="identifier">R</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">value</span><span class="special">);</span>  <span class="comment">// member only of generic promise template</span>
<span class="keyword">void</span> <span class="identifier">set_value</span><span class="special">(</span> <span class="identifier">R</span> <span class="special">&amp;&amp;</span> <span class="identifier">value</span><span class="special">);</span>      <span class="comment">// member only of generic promise template</span>
<span class="keyword">void</span> <span class="identifier">set_value</span><span class="special">(</span> <span class="identifier">R</span> <span class="special">&amp;</span> <span class="identifier">value</span><span class="special">);</span>       <span class="comment">// member only of promise&lt; R &amp; &gt; template</span>
<span class="keyword">void</span> <span class="identifier">set_value</span><span class="special">();</span>                 <span class="comment">// member only of promise&lt; void &gt; template</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl>
<dt><span class="term">Effects:</span></dt>
<dd><p>
                Store the result in the <a class="link" href="future.html#shared_state">shared state</a>
                and marks the state as ready.
              </p></dd>
<dt><span class="term">Throws:</span></dt>
<dd><p>
                <code class="computeroutput"><span class="identifier">future_error</span></code> with
                <code class="computeroutput"><span class="identifier">future_errc</span><span class="special">::</span><span class="identifier">future_already_satisfied</span></code> or <code class="computeroutput"><span class="identifier">future_errc</span><span class="special">::</span><span class="identifier">no_state</span></code>.
              </p></dd>
</dl>
</div>
<p>
          </p>
<h5>
<a name="promise_set_exception_bridgehead"></a>
  <span><a name="promise_set_exception"></a></span>
  <a class="link" href="promise.html#promise_set_exception">Member
          function <code class="computeroutput">set_exception</code>()</a>
</h5>
<p>
        </p>
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">set_exception</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">exception_ptr</span><span class="special">);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl>
<dt><span class="term">Effects:</span></dt>
<dd><p>
                Store an exception pointer in the <a class="link" href="future.html#shared_state">shared
                state</a> and marks the state as ready.
              </p></dd>
<dt><span class="term">Throws:</span></dt>
<dd><p>
                <code class="computeroutput"><span class="identifier">future_error</span></code> with
                <code class="computeroutput"><span class="identifier">future_errc</span><span class="special">::</span><span class="identifier">future_already_satisfied</span></code> or <code class="computeroutput"><span class="identifier">future_errc</span><span class="special">::</span><span class="identifier">no_state</span></code>.
              </p></dd>
</dl>
</div>
<p>
          </p>
<h5>
<a name="swap_for_promise_bridgehead"></a>
  <span><a name="swap_for_promise"></a></span>
  <a class="link" href="promise.html#swap_for_promise">Non-member function
          <code class="computeroutput">swap()</code></a>
</h5>
<p>
        </p>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">R</span> <span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">swap</span><span class="special">(</span> <span class="identifier">promise</span><span class="special">&lt;</span> <span class="identifier">R</span> <span class="special">&gt;</span> <span class="special">&amp;</span> <span class="identifier">l</span><span class="special">,</span> <span class="identifier">promise</span><span class="special">&lt;</span> <span class="identifier">R</span> <span class="special">&gt;</span> <span class="special">&amp;</span> <span class="identifier">r</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl>
<dt><span class="term">Effects:</span></dt>
<dd><p>
                Same as <code class="computeroutput"><span class="identifier">l</span><span class="special">.</span><span class="identifier">swap</span><span class="special">(</span>
                <span class="identifier">r</span><span class="special">)</span></code>.
              </p></dd>
</dl>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2013 Oliver Kowalke<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="future.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../futures.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="packaged_task.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
